<!--
 * @Author: wuzhen
 * @Date: 2019-12-04 17:56:54
 * @LastEditors  : wuzhen
 * @LastEditTime : 2020-01-11 10:53:29
 * @Description: 用户管理
 -->
<template>
  <Card style="width:100%" dis-hover>
    <p slot="title">
      <span class="primary">{{groupname}}</span>的聊天记录
    </p>
    <p slot="extra">
      <router-link to="/groupManagement">
        <Icon type="ios-arrow-back" /> 返回
      </router-link>
    </p>
   <!-- 搜索表头/表头按钮 -->
    <search-table :label-width="90" :search-props="searchProps" @handle-filter="handleFilter">
      <template v-slot:buttons>
        <Button type="error" @click="onDelete">批量删除</Button>
      </template>
    </search-table>
    <wz-table ref="table" :search-api="searchApi" :columns="columns" @on-selection-chang="onSelectionChang" :handle-btn="handleBtn">
      <template v-slot:action="slotProps">
        <Dropdown placement="bottom-start" @on-click="(e) => handleClick(e,slotProps.row)">
          <a href="javascript:void(0)">
            操作
            <Icon type="md-more" />
          </a>
          <DropdownMenu slot="list">
            <DropdownItem name="detail">查看用户</DropdownItem>
            <DropdownItem name="on">{{slotProps.row.status === 10?'帐户停用':'帐户启用'}}</DropdownItem>
            <DropdownItem name="offline" :disabled="slotProps.row.onlinestatus === 10">强制下线</DropdownItem>
            <DropdownItem name="offline">好友管理</DropdownItem>
            <DropdownItem name="offline">修改</DropdownItem>
          </DropdownMenu>
        </Dropdown>
      </template>
    </wz-table>
  </Card>
</template>
<script>
import index from "./mixins";
import { getGroupMsg,delMessageRecord } from "@/request/api";
export default {
  mixins: [index],
  data() {
    return {
      groupname: this.$route.query.groupname || "",
      searchApi: getGroupMsg,
      apiParams: {
        flipper: {
          offset: 0,
          limit: 15
        },
         bean: {},
        groupid: this.$route.params.id
      },
     // type: "mobile",
      //keyword: "",
       messageids: []
    };
  },
  mounted() {
    this.getData();
  },
  methods: {
    // 获取table数据
    getData() {
      this.$refs.table.getData(this.apiParams);
    },
    // 搜索
    handleFilter(params) {
      let apiParams = {};
      if (params.date && params.date.length && params.date[0]) {
        apiParams["createtime"] = {
          min: new Date(params.date[0] + " 00:00:00").getTime(),
          max: new Date(params.date[1] + " 23:59:59").getTime()
        };
      }
      apiParams = { ...apiParams, ...params };
      this.apiParams["bean"] = { ...apiParams };
      this.apiParams["bean"][this.type] = this.keyword;
      this.apiParams["flipper"] = {
        offset: 0,
        limit: 15,
        sort: "createtime desc"
      };
      this.getData();
    },
    // table选中
    onSelectionChang(e) {
      this.messageids = e.map(v => v.messageid);
    },
    // 删除
    onDelete() {
      if (!this.messageids.length) {
        this.$Message.warning("请选择要删除的记录");
        return;
      }
      this.$Modal.warning({
        title: "友情提示",
        content: "确定要删除记录？",
        closable: true,
        onOk: async () => {
          const res = await delMessageRecord({
            messageid: JSON.stringify(this.messageids)
          });
          if (res.code === 200) {
            this.$Message.success("操作成功");
            this.messageids = [];
            this.getData();
          }
        }
      });
    },
    handleClick(type, row) {
      this.id = row.userid;
      switch (type) {
        default:
          break;
      }
    }
  }
};
</script>
